Documentation for Users  2.1.2
Perception Toolbox for Virtual Reality (PTVR) Manual
laser_beam_axis.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 ...\PTVR_Researchers\Python_Scripts\Demos\Pointing\laser_beam_axis.py
4 
5 
6 Goal : show how to change the axis of the laser beam with respect to the
7  reference axis of the handcontroller.
8  This is achieved in the PointingLaser object with the
9  'laser_beam_x_y_rotation' parameter.
10  This modification only affects the VISUAL appearance of the laser beam.
11 
12  The axis of the laser beam can be defined with rotation coordinates or
13  with perimetric coordinates wrt the handcontroller reference axis.
14 
15 Task: Modify the values of 'my_laser_axis_wrt_handcontroller_reference_axis',
16  and see how it modifies the axis of the laser beam (this modification is
17  dependent on the headset manufacturer (see below) .
18 
19 Note 1:
20  For the the HTC Vive Pro series pointers, the reference axis
21  of the handcontroller is aligned with the long axis of the handcontroller.
22 
23  For the Quest 1, 2 and 3 headsets, the reference axis of
24  the handcontroller is tilted about the X axis of the handcontroller.
25 
26 Note 2:
27  In this demo, the laser beam is tilted by 45 degrees about the x axis
28  of the handcontroller (as specified by x and y rotations)
29 
30 Important note concerning scripts that use handcontrollers:
31  It is necessary to specify your VR system's manufacturer if:
32  a/ your code contains a PointedAt Event triggered by a handcontroller
33  or
34  b/ your code contains a PointingLaser () object.
35  This is specified in the The3DWorld() in the following way:
36  headset_manufacturer = "Vive" (default) refers to the HTC Vive pro series headsets.
37  headset_manufacturer = "Oculus" refers to the Quest 1, 2 or 3 headsets (in keeping
38  with OpenXR terminology).
39  For example:
40 my_world = The3DWorld (
41  headset_manufacturer = "Vive" # "Vive" by default
42  )
43 
44 
45 Things to check in the PointingLaser object when using different
46  headset manufacturers:
47  ex. With the Quest, you should do
48  laser_beam_x_y_rotation = np.array([60, 0]) # 60 ° about X axis
49  in the PointingLaser () object.
50  Otherwise the laserbeam will be directed upwards in an awkward and non
51  ergonomic direction.
52 
53 
54 """
55 
56 
57 from PTVR.Visual import The3DWorld
58 from PTVR.Stimuli.Scenes import VisualScene
59 import numpy as np
60 
61 from PTVR.Pointing.PointingCursor import PointingLaser
62 from PTVR.SystemUtils import LaunchThe3DWorld
63 
64 
65 # =============================================================================
66 # PARAMETERS #
67 # =============================================================================
68 
69 # Laser parameters
70 #
71 # Axis of laser beam with respect to the handcontroller reference axis.
72 # either perimetric coordinates : eccentricity and half-meridian (values from 0 to 360)
73 # or rotation values about x and y axes of the handcontroller (values from 0 to 360)
74 my_laser_axis_wrt_handcontroller_reference_axis = np.array([45, 0])
75  # the default is : np.array([45, 0])
76 # The two coordinates of this variable are interpreted as perimetric or
77 # rotation values depending on the following variable.
78 
79 
80 flag_x_y_rotation_coordinates = True
81 # Allows the interpretation of the 2 values in
82 # 'my_laser_axis_wrt_handcontroller_reference_axis'.
83 # if true -> rotations about the x and y axis
84 # if False -> perimetric coordinates (eccentricity and half-meridian)
85 
86 # =============================================================================
87 # END PARAMETERS #
88 # =============================================================================
89 
90 my_world = The3DWorld(
91  headset_manufacturer = "Vive"
92  # "Vive" (default) or "Oculus" or "ViveFocusVision"
93 )
94 # It is necessary to specify your VR system's manufacturer (here "Vive")
95 # in the The3DWorld() object if:
96 # a/ your code contains a PointedAt Event triggered by a handcontroller
97 # or
98 # b/ your code contains a PointingLaser () Object.
99 
100 
101 def main():
102 
103  my_scene = VisualScene(
104  is_right_hand_controller_visible = True,
105  )
106 
107  # Create a pointer
108  if (flag_x_y_rotation_coordinates == True): # x and y rotation coordinates
109  my_laser_beam = PointingLaser(
110  # x and y rotation values about x and y axes of the handcontroller (values from 0 to 360)
111  laser_beam_x_y_rotation = my_laser_axis_wrt_handcontroller_reference_axis
112  )
113  if (flag_x_y_rotation_coordinates == False): # perimetric coordinates
114  my_laser_beam = PointingLaser(
115  # perimetric coordinates : eccentricity and half-meridian (values from 0 to 360)
116  laser_beam_ecc_hm = my_laser_axis_wrt_handcontroller_reference_axis
117  )
118 
119  my_scene.place_pointing_laser(my_laser_beam)
120 
121  my_world.add_scene(my_scene)
122  my_world.write()
123 
124 
125 if __name__ == "__main__":
126  main()
127  LaunchThe3DWorld() # Launch the Experiment with PTVR.
def LaunchThe3DWorld(jsonFileCategory="Externals")
Definition: SystemUtils.py:182